<template>
  <div class="w-100 h-100" style="position: relative">
    <div
      style="width: 100%; height: 10%; position: absolute; top: 0; right: 0"
      class="d-flex justify-content-end"
    >
      <FakeLegend
        style="margin: auto 30px auto 0px"
        :color="colorSingleList"
        :text="['规划投资', '已完成投资']"
      >
      </FakeLegend>
    </div>
    <div class="bottom">
      <div id="tzwcqk" style="width: 100%; height: 100%"></div>
    </div>
  </div>
</template>

<script setup lang="ts">
import * as echarts from "echarts";
import { useOptions } from "@/hook/useOptions";
import FakeLegend from "@/components/project/fakeLegend.vue";
import {chartOptions} from '@/hook/chartOptions' 
const colorSingleList = ["rgba(3, 230, 254, 1)", "rgba(184, 235, 143, 1)"];


const jsonData: any = inject("jsonData");
const props = defineProps({
  typeValue: {
    default: 0,
  },
  yearValue: {
    default: 2024,
  },
  monthValue: {
    default: 1,
  },
});

const current = computed(() => {
  let data = [[], []];
  try {
    const allData = jsonData.value.jsgl.tzwcqk[props.yearValue];
    //年度
    if (props.typeValue === 0) {
      // debugger;
      Object.values(allData).forEach((d: any) => {
        d.forEach((arr: any, index: number) => {
          arr.forEach((c :number, i: number) => {
            const pre = data[index][i] || 0;
            data[index][i] = c + pre;
          });
        });
      });

      // debugger;
    } else {
      data = allData[props.monthValue];
    }
  } catch (error) {}

  return data;
});
let myChart1: any;

watch(
  () => current.value,
  (val) => {
    if (val) {
      myChart1.setOption({
        series: [{ data: val[0] }, { data: val[1] }],
      });
    }
  }
);


onMounted(() => {
  const option:any = chartOptions().twoBarOption(echarts, ['规划投资', '已完成投资'])
  option.xAxis[0].data = useOptions().projectTypeList.map((item) => item.label);
  option.yAxis[0].name = '万'
  myChart1 = echarts.init(document.getElementById("tzwcqk") as HTMLElement);
  myChart1.setOption(option);
});
</script>

<style lang="less" scoped>
.bottom {
  width: 100%;
  height: 100%;
  display: flex;
}
</style>
